/*
 * Driver.java
 */

package nxtgeninventorysystem;

import javax.swing.JTextField;
import nxtgeninventorysystem.Controller.Actions;
import nxtgeninventorysystem.Model.Database;
import nxtgeninventorysystem.View.Gui;
import org.jdesktop.application.Application;
import org.jdesktop.application.SingleFrameApplication;

/**
 * The driver class will provide an interface (main method) between the one
 * calling the program and the program itself.
 */
public class Driver extends SingleFrameApplication {

    /**
     * At startup create and show the main frame of the application.
     */
    @Override protected void startup() {
        show(new Gui(this));
        Gui.setStatusBarMessage("Ready");
        
        Thread dbconnectioncheck = new Thread() {
            @Override
            public void run() {
                Database.loadConnectionOptions();
                while(true) {
                    if(!(Database.isConnected()) && !(Gui.getDialog(Gui.Dialog.DatabaseConfiguration).isVisible())) {
                        Gui.setStatusBarMessage("Connect to database to continue...");
                        Gui.showDialog(Gui.Dialog.DatabaseConfiguration);
                    }
                    //System.out.println(((JTextField)(Gui.getComponent("itemNameValue"))).getText());
                }
            }
        };

        dbconnectioncheck.start();
    }

    /**
     * This method is to initialize the specified window by injecting resources.
     * Windows shown in our application come fully initialized from the GUI
     * builder, so this additional configuration is not needed.
     */
    @Override protected void configureWindow(java.awt.Window root) {
    }

    /**
     * A convenient static getter for the application instance.
     * @return the instance of Driver
     */
    public static Driver getApplication() {
        return Application.getInstance(Driver.class);
    }

    /**
     * Main method launching the application.
     */
    public static void main(String[] args) {
        launch(Driver.class, args);
    }
}
